package com.hyjx.framework.component.operatelog;

import com.hyjx.framework.common.CommonUtil;
import com.hyjx.framework.component.operatelog.operatelogdetail.OperatelogDetailModel;
import com.hyjx.framework.orm.dao.IBaseDao;
import com.hyjx.framework.orm.dao.Pager;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * 操作日志服务实现类
 */
@Service
@Transactional
public class OperatelogServiceImpl implements OperatelogService {

    @Resource
    private IBaseDao dao;

    @Override
    public String queryList(OperatelogModel model) {
        Pager pager = dao.getPager(model.getModuleName() + ".queryList", model.getModuleName() + ".queryCount", model);
        return CommonUtil.getPageJsonStr(pager);
    }

    @Override
    public boolean add(OperatelogModel model) {

        return dao.addObject(model.getModuleName() + ".insert", model);
    }

    @Override
    public OperatelogModel getInfoById(String s) {
        OperatelogModel model = null;
        model = (OperatelogModel) dao.queryObject(new OperatelogModel().getModuleName() + ".getInfoById", s);
        return model;
    }

    @Override
    public int edit(OperatelogModel model) {
        return dao.updateObject(model.getModuleName() + ".update", model);
    }

    @Override
    public int delete(String ids) {
        String[] id_array = ids.split(",");
        int num = 0;
        for (String id : id_array) {
            dao.deleteObject(new OperatelogModel().getModuleName() + ".delete", id);
            num++;
        }
        return num;
    }

    @Override
    public List<OperatelogModel> queryModelList(OperatelogModel operatelogModel) {
        return dao.queryObjectList(operatelogModel.getModuleName() + ".queryList");
    }

    @Override
    public List<OperatelogDetailModel> queryDetailModelList(OperatelogDetailModel odmodel) {
        return dao.queryObjectList(new OperatelogDetailModel().getModuleName() + ".queryList", odmodel);
    }

}
